#include <iostream>
#include <unistd.h>
#include <vector>
using namespace std;
const int NUM = 10;

void SubProcess()
{
    while(true)
    {
        cout << "我是子进程" << "pid : " << getpid() << " " << "ppid : " << getppid() << endl;
        sleep(1);
    }
}
int main()
{
    vector<pid_t> v;
    for(int i = 0;i < NUM;i++)
    {
        pid_t id = fork();
        if(id == 0)//子进程
        {
            SubProcess();
        }
        v.push_back(id);
    }
    //父进程
    cout << "我的全部子进程" << ": ";
    for(auto e : v)
    {
        cout << e << " ";
    }
    cout << endl;
    while(true)
    {
        cout << "我是父进程" << "pid : " << getpid() << " " << "ppid : " << getppid() << endl
;
        sleep(1);
    }
    
}
